package pl.edu.agh.neurony.logic;

import java.util.Formatter;

public class Connection {

	//fields
	private Neuron outputNeuron;
	private Neuron inputNeuron;
	private Double weight = null;
	public Double previousChange = 0.0;
	
	public void setWeight(Double weight) {
		this.weight = weight;
	}

	//constructors
	public Connection(Neuron inputNeuron, Neuron outputNeuron) {
		this.outputNeuron = outputNeuron;
		this.inputNeuron = inputNeuron;
	}
	
	//getters
	public Neuron getOutputNeuron() {return outputNeuron;}
	public Neuron getInputNeuron() {return inputNeuron;}
	public double getWeight() {return weight;}
	
	//setters
	public void setWeight(double weight) {this.weight = weight;}
	
	//public methods
	public void disconnect() {
		outputNeuron.inputConnections.remove(this);
		outputNeuron.outputConnections.remove(this);
		inputNeuron.inputConnections.remove(this);
		inputNeuron.outputConnections.remove(this);
	}
	
	public boolean isValid() {
		return weight != null;
	}
	
	@Override
	public String toString() {
		if (weight != null) {
			Formatter f = new Formatter();
			f.format("%1.2f", weight);
			return f.toString();
			
		}
		return "not assigned";
	}

	public void setInputNeuron(Neuron neuron) {
		inputNeuron = neuron;
	}
}
